/**
 * 订单状态定义
 */
interface OrderStatusDefinition {
  /** 状态标签 */
  label: string;
  /** 状态值 */
  value: string;
  /** 是否为默认状态 */
  isDefault: string;
  /** 表格回显样式 */
  tableDisplayStyle?: string;
  /** 其他样式 */
  style?: string;
  /** 渲染颜色 */
  color: string;
}

interface IOrderStatus {
  NEW_ORDER: OrderStatusDefinition;
  DISPATCHED: OrderStatusDefinition;
  WAITING_FOR_DELIVERY: OrderStatusDefinition;
  DELIVERING: OrderStatusDefinition;
  RECEIVED: OrderStatusDefinition;
  RETURNING: OrderStatusDefinition;
  RETURNED: OrderStatusDefinition;
  COMPLETED: OrderStatusDefinition;
  CANCELLED: OrderStatusDefinition;
}

/**
 * 订单状态常量
 */
const OrderStatus: IOrderStatus = {
  NEW_ORDER: {
    label: "新订单",
    value: "1",
    isDefault: "1",
    color: "#fd7e14"
  },
  DISPATCHED: {
    label: "已派单",
    value: "2",
    isDefault: "1",
    color: "#17a2b8"
  },
  WAITING_FOR_DELIVERY: {
    label: "待发货",
    value: "3",
    isDefault: "1",
    color: "#fa8c16"
  },
  DELIVERING: {
    label: "送货中",
    value: "4",
    isDefault: "1",
    color: "#007bff"
  },
  RECEIVED: {
    label: "已收货",
    value: "5",
    isDefault: "1",
    color: "#28a745"
  },
  RETURNING: {
    label: "退货中",
    value: "6",
    isDefault: "1",
    color: "#ffc107"
  },
  RETURNED: {
    label: "已退货",
    value: "7",
    isDefault: "1",
    color: "#dc3545"
  },
  COMPLETED: {
    label: "完成",
    value: "8",
    isDefault: "1",
    color: "#28a745"
  },
  CANCELLED: {
    label: "已取消",
    value: "9",
    isDefault: "1",
    color: "#dc3545"
  }
} as const;

const OrderOptions: Record<string, { color: string; text: string }> = {
  '1': {color: '#fd7e14', text: '新订单'},  // 橙色
  '2': {color: '#17a2b8', text: '已派单'},  // 青色
  '3': {color: '#fa8c16', text: '待发货'},  // 橙色
  '4': {color: '#007bff', text: '送货中'},  // 蓝色
  '5': {color: '#28a745', text: '已收货'},  // 绿色
  '6': {color: '#ffc107', text: '退货中'},  // 黄色
  '7': {color: '#dc3545', text: '已退款'},  // 红色
  '8': {color: '#28a745', text: '已完成'},   // 绿色
  '9': {color: '#dc3545', text: '已取消'},   // 红色
};

/**
 * 订单状态值类型
 */
type OrderStatusValue = typeof OrderStatus[keyof typeof OrderStatus]["value"];

/**
 * 根据状态值获取状态定义
 * @param value 状态值
 * @returns 状态定义对象
 */
function getOrderStatusDefinition(value: string): OrderStatusDefinition | undefined {
  return Object.values(OrderStatus).find(status => status.value === value);
}

/**
 * 获取所有状态值
 * @returns 状态值数组
 */
function getAllOrderStatusValues(): OrderStatusValue[] {
  return Object.values(OrderStatus).map(status => status.value);
}

/**
 * 获取所有状态定义
 * @returns 状态定义数组
 */
function getAllOrderStatusDefinitions(): OrderStatusDefinition[] {
  return Object.values(OrderStatus);
}

export {
  OrderStatus,
  OrderStatusValue,
  getOrderStatusDefinition,
  getAllOrderStatusValues,
  getAllOrderStatusDefinitions,
  OrderOptions
};
